package com.woniu.order.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.order.client.CartQueryClient;
import com.woniu.order.client.result.CartQueryResultInfo;
import com.woniu.order.service.CartService;
import com.woniu.order.service.dto.CartItemDto;
import com.woniu.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
public class CartQueryApiImpl implements CartQueryClient {
    @Resource
    private CartService cartService;

    /**
     * 查看本人购物车
     *
     * @return
     */
    @Override
    public Result<List<CartQueryResultInfo>> searchCarts(Integer userId) {
        List<CartItemDto> cartItemDtos = cartService.searchCarts(userId);
        List<CartQueryResultInfo> cartQueryResultInfos = BeanUtil.copyToList(cartItemDtos, CartQueryResultInfo.class);
        return Result.getInstanceList(CartQueryResultInfo.class).setData(cartQueryResultInfos);
    }
}
